package com.zhugang.week01;

/**
 * @program algorithms
 * @description: drink
 * @author: chanzhugang
 * @create: 2022/03/13 22:43
 */
public class Drink {

    public static void main(String[] args) {
        Drink drink = new Drink();
        int count = drink.drink(6);
        System.out.println(count);
    }

    /**
     * 现有x瓶瓶酒，每3个空瓶子换一瓶瓶酒，每7个瓶盖子也能换一瓶瓶酒，问最后能喝多少瓶瓶酒(阿里钉钉)
     */
    public int drink(int x) {
        // 能喝多少瓶
        int count = x;
        // 空瓶子
        int k1 = x;
        // 瓶盖子
        int k2 = x;
        while (k1 >= 3 || k2 >= 7) {
            if (k1 >= 3) {
                int change = k1 / 3;
                count += change;
                k1 %= 3;
                k1 += change;
                k2 += change;
            }
            if (k2 >= 7) {
                int change = k2 / 7;
                count += change;
                k2 %= 7;
                k1 += change;
                k2 += change;
            }
        }
        return count;
    }
}